package com.lc.zpyh.ui.activity.home;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.umeng.Platform;
import com.lc.umeng.UmengShare;
import com.lc.zpyh.R;
import com.lc.zpyh.app.AppActivity;
import com.lc.zpyh.http.request.ShareSelectByTypeApi;
import com.lc.zpyh.http.response.ShareSelectByTypeBean;
import com.lc.zpyh.other.IntentKey;
import com.lc.zpyh.ui.dialog.ShareDialog;
import com.lc.zpyh.util.SPUtil;
import com.lc.zpyh.widget.UIHelper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class InviteFriendsActivity extends AppActivity {
    List<String> dataBeanList = new ArrayList<>();
    @BindView(R.id.img_fenxiang)
    ImageView imgFenxiang;
    @BindView(R.id.tv_yaoqingma)
    TextView tvYaoqingma;
    @BindView(R.id.tv_lookfans)
    TextView tvLookfans;
    private String title;
    private String description;
    private String logo;
    private String url;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_invitefriends;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        tvYaoqingma.setText(SPUtil.get(this, IntentKey.INVITECODE,""));
        shareSelectByType();
    }

    private void shareSelectByType() {
        EasyHttp.post(this)
                .api(new ShareSelectByTypeApi().setType("下载").setId("")).request(new HttpCallback<ShareSelectByTypeBean>(this) {

            @Override
            public void onSucceed(ShareSelectByTypeBean data) {
                if (data.getCode() == 0) {
                    title = data.getList().getTitle();
                    description = data.getList().getContent();
                    logo = data.getList().getImg();
                    if (data.getList().getUrl().contains("http")){
                        url = data.getList().getUrl();
                    }else {
                        url = "https://www.baidu.com";
                    }

                }
            }
                @Override
                public void onFail(Exception e) {
                    super.onFail(e);

                }
            });
    }

    @Override
    protected boolean isStatusBarEnabled() {
        return false;
    }

    @OnClick({R.id.img_fenxiang, R.id.tv_lookfans,R.id.image_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_fenxiang:
                new ShareDialog.Builder(this)
                        // 分享标题
                        .setShareTitle(title)
                        // 分享描述
                        .setShareDescription(description)
                        // 分享缩略图
                        .setShareLogo(IntentKey.CAR_IMAGE+logo)
                        // 分享链接
                        .setShareUrl(url)
                        .setListener(new UmengShare.OnShareListener() {

                            @Override
                            public void onSucceed(Platform platform) {
                                toast("分享成功");
                            }

                            @Override
                            public void onError(Platform platform, Throwable t) {
                                toast("分享出错");
                            }

                            @Override
                            public void onCancel(Platform platform) {
                                toast("分享取消");
                            }
                        })
                        .show();
                break;
            case R.id.tv_lookfans:
                UIHelper.startActivity(this,MyFansActivity.class);
                break;
            case R.id.image_back:
              finish();
                break;
        }
    }
}
